<?php
namespace app\adminweb\controller;
use think\Controller;
header("Access-Control-Allow-Origin: * ");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
class Upload
{
    //文章上传
    public function index(){
        // 获取表单上传文件
        $files = request()->file('image');
        if(count($files)>=2){
            foreach($files as $file){
                // 移动到框架应用根目录/uploads/ 目录下
                $info = $file->move( '../public/static/upload/file');
                if($info){
                    // 输出 42a79759f284b767dfcb2a0197904287.jpg
                    $url = $info->getSaveName();
                    $urlparh[] = '/static/upload/file/'.$url;
                }else{
                    // 上传失败获取错误信息
                    $urlparh = $file->getError();
                }
            }
        }else{
            $info = $files->move( '../public/static/upload/file');
            if($info){
                $url = $info->getSaveName();
                $urlparh[] = '/static/upload/file/'.$url;
            }else{
                // 上传失败获取错误信息
                $urlparh = $files->getError();
            }
        }
        $array = array('code'=>1,'msg' =>'上传成功','imgUrl'=>$urlparh);
        return $array;
    }
}
